package com.dbh.alg.datastructure.stack;

/**
 * @author dongbanghui
 * @date 2025/5/29
 */
public class E04Leetcode232 {

    ArrayStack<Integer>  s1 = new ArrayStack<>(100);
    ArrayStack<Integer>  s2 = new ArrayStack<>(100);

    public void push(int x) {
        // 将元素压入s1
        s1.push(x);
    }

    public int pop() {
        if (s2.isEmpty()) {
            while (!s1.isEmpty()) {
                // 将s1中的元素全部弹出并压入s2
                s2.push(s1.pop());
            }
        }
        return s2.pop();
    }

    public int peek() {
        if (s2.isEmpty()) {
            while (!s1.isEmpty()) {
                // 将s1中的元素全部弹出并压入s2
                s2.push(s1.pop());
            }
        }
        return s2.peek();
    }

    public boolean empty() {
        // 队列为空的条件是s1和s2都为空
        return s1.isEmpty() && s2.isEmpty();
    }

}
